OSSFile = function(ui, data, title)
{
    DrawioFile.call(this, ui, data);

    this.title = title;
};

mxUtils.extend(OSSFile, DrawioFile);

OSSFile.prototype.getMode = function()
{
    return App.MODE_OSS;
};

OSSFile.prototype.getTitle = function()
{
    return this.title;
};

OSSFile.prototype.getHash = function()
{
    return 'O' + encodeURIComponent(this.getTitle());
};

OSSFile.prototype.isRenamable = function()
{
    return false;
};

OSSFile.prototype.isAutosave = function()
{
    return false;
};

OSSFile.prototype.save = function(revision, success, error)
{
    this.saveAs(this.title, success, error);
};

OSSFile.prototype.saveAs = function(title, success, error)
{
    DrawioFile.prototype.save.apply(this, arguments);
    this.saveFile(title, false, success, error);
};



//revision 修订
OSSFile.prototype.saveFile = function(title, revision, success, error)
{
    var _this = this;
    if (!_this.isEditable())
    {
        if (success != null)
        {
            success();
        }
    }
    else
    {
        var htId = urlParams['htId'];
        this.ui.oss.sendRequest(this.ui.oss.saveUri,
            JSON.stringify({
                htId: htId,
                title: title,
                xmlFileData: this.getData()
            }), "POST",
            function(req){
                if(req.code == 200){
                    _this.setModified(false);
                    _this.contentChanged();
                    urlParams['htId'] = req.data.htId;
                    urlParams['htBbId'] = req.data.htBbId;
                    history.replaceState(null , null , '?htId=' + req.data.htId + "&htBbId=" + req.data.htBbId + "#O" + title);
                    if (success != null)
                    {
                        success();
                    }
                } else {
                    _this.ui.handleError({message: req.message}, mxResources.get('errorSavingFile'), mxUtils.bind(this, function()
                    {
                        var tempFile = _this.ui.getCurrentFile();
                        window.location.hash = (tempFile != null) ? tempFile.getHash() : '';
                    }));
                }
            },
            function(error){
                _this.ui.handleError({message: mxResources.get('ServerNotRespondingOrToknExpire')}, mxResources.get('errorSavingFile'));
                _this.ui.spinner.stop();
            }
        )
    }
};


/*OSSFile.prototype.rename = function(title, success, error)
{
    console.log('重命名操作');
    var oldTitle = this.getTitle();
    console.log('原来的文件名', oldTitle);
    console.log('现在的文件名', title);
};*/



